﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace diploma.core.localize
{
    /// <summary>
    /// 
    /// </summary>
    public class AbstractDictionary
    {
        /// <summary>
        /// 
        /// </summary>
        protected Dictionary<string, string> dict = null;

        /// <summary>
        /// 
        /// </summary>
        protected AbstractDictionary()
        {
            dict = new Dictionary<string, string>();
            init();
        }

        /// <summary>
        /// 
        /// </summary>
        protected virtual void init()
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="val"></param>
        public void AddLocalization(string key, string val)
        {
            if (!dict.ContainsKey(key)) dict.Add(key, val);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <param name="val"></param>
        public void ModifyLocalization(string key, string val)
        {
            if (dict.ContainsKey(key)) dict[key] = val;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        public void RemoveLocalization(string key)
        {
            if (dict.ContainsKey(key)) dict.Remove(key);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public bool ContainWord(string key)
        {
            return dict.ContainsKey(key);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public string this[string key]
        {
            get
            {
                if (this.dict.ContainsKey(key))
                {
                    return this.dict[key];
                }
                return key;
            }
            protected set
            {
                if (this.dict.ContainsKey(key))
                {
                    ModifyLocalization(key, value);
                }
                else
                {
                    AddLocalization(key, value);
                }
            }
        }

    }
}
